package rm.ep.shared;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Parent;
import com.googlecode.objectify.annotation.Unindexed;

@SuppressWarnings("serial")
public class BlobEntity extends AbstractEntity {

	@Unindexed 
	private byte[] fFile;
	
	@Parent
	private Key<FileEntity> fParent;
	
	protected BlobEntity() {
		// required empty constructor
	}
	
	public BlobEntity(byte[] file, Key<FileEntity> parent) {
		fFile = file;
		fParent = parent;
	}
	
	public byte[] getFile() {
		return fFile;
	}
	
	public Key<FileEntity> getParent() {
		return fParent;
	}
	
	@Override
	public int hashCode() {
		return super.hashCode() + 13 * getClass().getName().hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		if (obj instanceof BlobEntity) {
			BlobEntity that = (BlobEntity) obj;
			return getId().equals(that.getId());
		}
		return false;
	}
	
}
